package  com.hemi.rhet;


import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;

import android.content.Context;
import android.widget.Toast;


public     class ParamUtil {
	   public static String msgMapToString(HashMap rsmgMap){
	    	StringBuffer sb = new StringBuffer("");
	    	Set<String> st = rsmgMap.keySet();
	    	Iterator<String> it = st.iterator();
	    	while(it.hasNext())
	    	{
	    		String key = it.next();
	    		if(!"".equals(sb.toString()))
	    		{
	    			sb.append("&");
	    		}
	    		sb.append(key+"="+rsmgMap.get(key));
	    	}
	    	
	    	return sb.toString();
	    }
	   
	   public static HashMap stringTomsgMap(String message){
		   HashMap rmap = new HashMap();
		   
	    	 if(message!=null)
	    	 {
	    		String[] fidv =  message.split("&");
	    		for(String dv:fidv){
	    			if(-1!=dv.indexOf("=")){
	    				String[] kvs = dv.split("=");
	    				rmap.put(kvs[0], kvs[1]);
	    			}
	    		}
	    	 }
	    	return rmap;
	    }
	   
	   public static String getDatedFileName(String fname) {
			StringBuffer result = new StringBuffer();

			SimpleDateFormat df = new SimpleDateFormat("yyMMddHHmmss");
			String dateSfx = "_" + df.format(new Date());

			int idx = fname.lastIndexOf('.');
			if (idx != -1) {
				result.append(fname.substring(0, idx));
				result.append(dateSfx);
				result.append(fname.substring(idx));
			} else {
				result.append(fname);
				result.append(dateSfx);
			}

			return result.toString();
		}
	   
	   
	   public static void showMessage(Context ctx , String message){
		   
		   Toast.makeText(ctx, message,
                   Toast.LENGTH_LONG).show();
	   }
	   public static void main(String[] args)
	   {
		   System.out.println(msgMapToString(stringTomsgMap("name=1111&ag=2323&fad")));
		   
		   
	   }
	   
}
